# Dickstein, Ho, and Mark (2023)
# This script creates the figures and tables.

# Setting preliminaries
module remove R
module load R/4.0.2
WORK=$(pwd)

# Summary statistics, markups, and costs 
# Tables 1, 2.
# Figures 1, 2, 3.
cd $WORK/source/paper_sumstats
stata -b main.do

# Derived estimates - moral hazard and risk aversion
# Table 5.
cd $WORK/source/derived_paramests
Rscript tab_derived_param.R

# Adjusted markups
# Figure 4. 
cd $WORK/source/adj_markups
Rscript creating_adjmarkup_data.R
stata -b create_boxplots.do

# Derived estimates: non-discretionary spending
# Table 4. 
cd $WORK/source/ctftparams
Rscript create_ctftparams.R
stata -b create_ctftparams_tab.do

# Change in consumer surplus figures across parameter values
# Figures 5, 6, and 7.
cd $WORK/source/heatmaps
Rscript create_heatmapdata.R
Rscript create_heatmaps_andbuildata.R
stata -b create_stataplots.do

# ~ # ~ # ~ # ~ # ~ # ~ # ~ # ~ #    

# Getting tables publication ready
cd $WORK/createlatextables
Rscript main.R

# Pull the publication ready figures into one place
cd $WORK/pubfigures
## Figure 1
mkdir $WORK/pubfigures/mainf_costs
cp $WORK/release/paper_sumstats/plots/mainf_costs/*.eps  $WORK/pubfigures/mainf_costs
## Figure 2
mkdir $WORK/pubfigures/mainf_prem
cp $WORK/release/paper_sumstats/plots/mainf_prem/*.eps  $WORK/pubfigures/mainf_prem
## Figure 3
mkdir $WORK/pubfigures/mainf_markups
cp $WORK/release/paper_sumstats/plots/mainf_markups/*.eps  $WORK/pubfigures/mainf_markups
## Figure 4
mkdir $WORK/pubfigures/adj_markups
cp $WORK/release/adj_markups/*.eps  $WORK/pubfigures/adj_markups
## Figures 5 and 6
mkdir $WORK/pubfigures/heatmaps
cp $WORK/release/heatmaps/*.eps  $WORK/pubfigures/heatmaps
## Figure 7
cp $WORK/release/heatmaps/stata_plots/*.eps  $WORK/pubfigures/heatmaps
